<%@tag description="Displays a Layer and its children in KML" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/WEB-INF/taglib/wms2kml" prefix="wms2kml"%>
<%@attribute name="capabilities" required="true" type="uk.ac.rdg.resc.wms2kml.WMSCapabilities" description="Capabilities object"%>
<%@attribute name="layer" required="true" type="uk.ac.rdg.resc.wms2kml.Layer" description="Layer object"%>
<%@attribute name="baseURL" required="true" description="URL to use as a base for any callbacks to this server, e.g. in NetworkLinks"%>
<c:if test="${layer.includeInKml}">
    <c:choose>
        <c:when test="${empty layer.children}">
            <c:if test="${not empty layer.name}">
                <wms2kml:displayableLayer capabilities="${capabilities}" layer="${layer}" baseURL="${baseURL}"/>
            </c:if>
        </c:when>
        <c:otherwise>
            <%-- A "container" layer --%>
            <Folder>
                <name>${layer.title}</name>
                <description>${layer.description}</description>
                <visibility>0</visibility>
                <c:if test="${not empty layer.name}">
                    <wms2kml:displayableLayer capabilities="${capabilities}" layer="${layer}" baseURL="${baseURL}"/>
                </c:if>
                <c:if test="${not empty layer.children}">
                    <c:forEach items="${layer.children}" var="child">
                        <wms2kml:layer capabilities="${capabilities}" layer="${child}" baseURL="${baseURL}"/>
                    </c:forEach>
                </c:if>
            </Folder>
        </c:otherwise>
    </c:choose>
</c:if>